from django.contrib.auth.models import User
from django.db import models
from django.db.models import CASCADE

# Create your models here.


class FeedBack(models.Model):
    # 数据库中： 属性==>字段
    quality = models.IntegerField(verbose_name="商品质量", default=1)
    attitude = models.IntegerField(verbose_name="客服态度", default=1)
    speed = models.IntegerField(verbose_name="物流速度", default=1)
    text = models.TextField(verbose_name="评论内容", default="")
    annoy = models.BooleanField(verbose_name="是否匿名", default=True)
    # 将评论表和用户表关联(哪个评论是哪个用户的、同一个用户只能提交1次评论、只有用户自己能修改自己的评论内容)
    user = models.ForeignKey(User, default=1, on_delete=CASCADE)

    name: str = "小妮"  # 普通属性
    objects: models.QuerySet  # 普通属性

    class Meta:
        # verbose_name = "用户评价"
        # verbose_name_plural = "用户评价"  # 复数时的显示
        # 优化后的写法
        verbose_name = verbose_name_plural = "用户评价"

    def __str__(self):
        return f"商品评论({self.id})"  # 打印object的时候按照我们自己的需求来打印

    #   不进行设置的话,打印object默认的输出是:FeedBack object (37)


# 练习用
class Student(models.Model):
    GENDER_CHOICES = [(1, "男"), (0, "女")]

    s_id = models.AutoField(verbose_name="ID", primary_key=True)  # 自增主键
    s_name = models.CharField(verbose_name="姓名", max_length=20, default="")
    s_birth = models.CharField(verbose_name="出生日期", max_length=20, default="")
    s_sex = models.IntegerField(verbose_name="性别", choices=GENDER_CHOICES, default=1)

    objects: models.QuerySet  # 普通属性

    class Meta:
        db_table = "Student"


class Course(models.Model):
    c_id = models.CharField(max_length=20, primary_key=True)
    c_name = models.CharField(max_length=20, default="")
    t_id = models.CharField(max_length=20)

    class Meta:
        db_table = "Course"


class Teacher(models.Model):
    t_id = models.CharField(max_length=20, primary_key=True)
    t_name = models.CharField(max_length=20, default="")

    class Meta:
        db_table = "Teacher"


class Score(models.Model):
    id = models.AutoField(primary_key=True)  # 新增自增主键
    s_id = models.CharField(max_length=20)  # 学生 id
    c_id = models.CharField(max_length=20)  # 课程 id
    s_score = models.PositiveSmallIntegerField()  # 分数 0-100

    class Meta:
        db_table = "Score"
        # 保留原联合唯一约束（相当于原联合主键）
        unique_together = (("s_id", "c_id"),)
